<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Board Demo</title>
  </head>
  <body>
    <div>
      <label for="id"
        >Extension ID (Access: chrome://extensions/ and toggle developer mode on
        to get the ID):
      </label>
      <input type="text" placeholder="Enter Extention ID2" id="id" />
    </div>
    <hr />
    <div>
      <button id="login-button">Login1</button>
      <button id="logout-button">Logout</button>
    </div>
    <pre id="payload-preview"></pre>
  </body>

  <script defer>
    function sendMessageToExtension(payload,resp) {
      const extensionIdField = document.querySelector("#id");

      if (chrome && chrome.runtime) {
        chrome.runtime.sendMessage(
          extensionIdField.value || "nfoddpmcmcgidocmelbgdapjjiooajkp",
          payload,
          resp
        );
      }
    }
    const loginButton = document.querySelector("#login-button");
    const logoutButton = document.querySelector("#logout-button");
    const payloadPreview = document.querySelector("#payload-preview");
    var r = ""
    loginButton.onclick = () => {
      const payload = { type: "LOG_IN", token: "xxx" };
      console.log("loginButton onClick")
      
      sendMessageToExtension(payload,function(response){
        console.log("plugin response:",response)
        r = response
      });
      payloadPreview.innerHTML = "<p>Sent: " + JSON.stringify(payload)+"</p>"+"<p>Resp:"+JSON.stringify(r)+"</p>"
    };

    logoutButton.onclick = () => {
      const payload = { type: "LOG_OUT" };

      sendMessageToExtension({ type: "LOG_OUT" });
      payloadPreview.innerHTML = "Sent: " + JSON.stringify(payload);
    };
  </script>
</html>